package cn.lyb;

import cn.lyb.cache.AgentCache;
import cn.lyb.common.RequestFilterParam;
import cn.lyb.entity.AgentEntity;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;


@RunWith(SpringRunner.class)
@SpringBootTest
/**
 * 测试缓存是否写入Redis中
 * 第一次执行会执行方法,并将执行结果缓存到Redis中
 * 第二次执行直接从Redis中取数据
 * @author luckyman
 */
public class RedisHashCacheDemoTestBoot {
    @Autowired
    private AgentCache agentCache;

    @Test
    public void getAll() {
        System.out.println(agentCache.getAll());
    }

    @Test
    public void getById() {
        System.out.println(agentCache.getOneById(218));
    }

    @Test
    public void editById() {
        AgentEntity agentEntity = new AgentEntity()
                .setId(217)
                .setName("测试修改2020年1月31日 03:53:30");
        agentCache.editById(agentEntity);
    }

    @Test
    public void removeById() {
        agentCache.removeOneById(218);
    }

    /**
     * 测试过滤条件,分页
     */
    @Test
    public void testRequestFilter() {
        RequestFilterParam<AgentEntity> filterParam = new RequestFilterParam<>();
        filterParam.setPageNum(1);
        filterParam.setPageSize(10);
        filterParam.setFilter(new AgentEntity());
        IPage<AgentEntity> byFilter = agentCache.getByFilter(filterParam);
        System.out.println(byFilter.getRecords());
    }


}
